home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v7n22.arc / MOUSDEMO.ARC / MOUSDEMO.C < prev    next >
C/C++ Source or Header  |  1988-12-07  |  4KB  |  113 lines

  1. /*-----------------------------------------------------
  2.    MOUSDEMO.C -- Demonstrates mouse message processing
  3.                  (c) 1988, Ziff Communications Co.
  4.                  PC Magazine * Charles Petzold, 9/88
  5.   -----------------------------------------------------*/
  6.  
  7. #define INCL_WIN
  8. #define INCL_GPI
  9. #include <os2.h>
  10. #include <stdio.h>
  11. #define ID_TIMER    1
  12.  
  13. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  14. HAB  hab ;
  15.  
  16. int main (void)
  17.      {
  18.      static CHAR szClientClass [] = "MousDemo" ;
  19.      HMQ         hmq ;
  20.      HWND        hwndFrame, hwndClient ;
  21.      QMSG        qmsg ;
  22.      ULONG       flFrameFlags = FCF_STANDARD & ~FCF_MENU ;
  23.  
  24.      hab = WinInitialize (0) ;
  25.      hmq = WinCreateMsgQueue (hab, 0) ;
  26.  
  27.      WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
  28.  
  29.      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
  30.                                      &flFrameFlags, szClientClass,
  31.                                      "Mouse Demo",
  32.                                      0L, NULL, 0, &hwndClient) ;
  33.  
  34.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  35.           WinDispatchMsg (hab, &qmsg) ;
  36.  
  37.      WinDestroyWindow (hwndFrame) ;
  38.      WinDestroyMsgQueue (hmq) ;
  39.      WinTerminate (hab) ;
  40.      return 0 ;
  41.      }
  42.  
  43. VOID PaintWindow (HWND hwnd, HPS hps, SHORT xPointer, SHORT yPointer)
  44.      {
  45.      static CHAR szBuffer [40] ;
  46.      RECTL       rcl ;
  47.  
  48.      sprintf (szBuffer, "      Pointer Position = (%d, %d)      ",
  49.               xPointer, yPointer) ;
  50.      WinQueryWindowRect (hwnd, &rcl) ;
  51.      GpiSetBackMix (hps, BM_OVERPAINT) ;
  52.      WinDrawText (hps, -1, szBuffer, &rcl, CLR_NEUTRAL, CLR_BACKGROUND,
  53.                   DT_CENTER | DT_VCENTER) ;
  54.      }
  55.  
  56. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  57.      {
  58.      static SHORT xPointer, yPointer ;
  59.      HPS          hps;
  60.      POINTL       ptl ;
  61.  
  62.      switch (msg)
  63.       {
  64.           case WM_CREATE:
  65.                WinStartTimer (hab, hwnd, ID_TIMER, 1000) ;
  66.                return 0 ;
  67.  
  68.           case WM_TIMER:
  69.                WinQueryPointerPos (HWND_DESKTOP, &ptl) ;
  70.                WinMapWindowPoints (HWND_DESKTOP, hwnd, &ptl, 1) ;
  71.                xPointer = (SHORT) ptl.x ;
  72.                yPointer = (SHORT) ptl.y ;
  73.  
  74.                hps = WinGetPS (hwnd) ;
  75.                PaintWindow (hwnd, hps, xPointer, yPointer) ;
  76.                WinReleasePS (hps) ;
  77.                return 0 ;
  78.  
  79.           case WM_MOUSEMOVE:
  80.                xPointer = MOUSEMSG(&msg)->x ;
  81.                yPointer = MOUSEMSG(&msg)->y ;
  82.  
  83.                hps = WinGetPS (hwnd) ;
  84.                PaintWindow (hwnd, hps, xPointer, yPointer) ;
  85.                WinReleasePS (hps) ;
  86.                break ;
  87.  
  88.           case WM_BUTTON1DOWN:
  89.                DosBeep (256, 100) ;
  90.                break ;
  91.  
  92.           case WM_BUTTON1UP:
  93.                DosBeep (512, 100) ;
  94.                return 0 ;
  95.  
  96.           case WM_BUTTON1DBLCLK:
  97.                DosBeep (1024, 100) ;
  98.                return 0 ;
  99.  
  100.           case WM_PAINT:
  101.                hps = WinBeginPaint (hwnd, NULL, NULL) ;
  102.                GpiErase (hps) ;
  103.                PaintWindow (hwnd, hps, xPointer, yPointer) ;
  104.                WinEndPaint (hps) ;
  105.                return 0 ;
  106.  
  107.           case WM_DESTROY:
  108.                WinStopTimer (hab, hwnd, ID_TIMER) ;
  109.                return 0 ;
  110.           }
  111.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  112.      }
  113.